package com.cc.mall.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@ToString
@ApiModel("购物车")
public class Cart {
    /**
     * 购物车中商品详情的总数
     */
    @ApiModelProperty("商品总数")
    private Integer countNum;
    /**
     * 购物车所有商品详情的总价格
     */
    @ApiModelProperty("总价格")
    private BigDecimal totalAmount;

    public Integer getCountNum() {
        Integer sum = 0;
        for (CartItem cartItem : this.cartItemList) {
            sum = sum+cartItem.getCount();
        }
        return sum;
    }

    public void setCountNum(Integer countNum) {
        this.countNum = countNum;
    }
    @ApiModelProperty("购物项集合")
    private List<CartItem> cartItemList = new ArrayList<>();

    public BigDecimal getTotalAmount() {
        BigDecimal count = new BigDecimal("0");
        for (CartItem cartItem : this.cartItemList) {
            if(cartItem.getCheck())
                count = count.add(cartItem.getTotalPrice());
        }
        return count;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public List<CartItem> getCartItemList() {
        return cartItemList;
    }

    public void setCartItemList(List<CartItem> cartItemList) {
        this.cartItemList = cartItemList;
    }
}
